---护盾
---@class BuffEffect6 : BaseBuffEffect
BuffEffect6 = ClientFight.CreateClass("BuffEffect6", ClientFight.BaseBuffEffect)
local t = BuffEffect6
t.EffectType = 6
---@param fight Fighter
---@param buff FighterBuff
function t:add(fight, buff)
    local source = buff.source
    local target = buff.target
    local baseValue = 0;
    local targetType = 0;
    local attrType = 0;
    local attrRatio = 0;
    local f_BuffEffectValue = buff.buffBean.f_BuffEffectValue
    if (f_BuffEffectValue ~= nil and #f_BuffEffectValue > 0) then
        baseValue = f_BuffEffectValue[1];
        targetType = f_BuffEffectValue[2];
        attrType = f_BuffEffectValue[3];
        attrRatio = f_BuffEffectValue[4];
    else
        baseValue = tonumber(buff.addParameters[1])
        targetType = tonumber( buff.addParameters[2])
        attrType = tonumber( buff.addParameters[3])
        attrRatio = tonumber( buff.addParameters[4])
    end

    local fighter = targetType == 0 and source or target;
    local value = baseValue;
    if (attrType > 0) then
        value = value + math.floor(FighterAttributeManager.getFightAttr(fighter, attrType) * Utils.toRatio(attrRatio));
    end
    value = value * buff.overlay
    --buff.setParameter(new int[] { value });
    buff.pool.type = BuffPoolEnum.DEFEAT
    value = buff.pool:setCurrent(value,buff);
    buff.pool:setMax(value);
    local logv = value;
    SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. target.fighterId
    .." Buff" .. buff.modelId .. " 增加护盾BUFF效果，护盾值：" .. logv);

    return ClientFight.BaseBuffEffect.add(self,fight, buff);
end

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = { ... }
    local trigger = parameters[1];
    local result = parameters[3];

    local skill =  parameters[2];
    local skillBean = skill.skill.skillBean
    if (skillBean.f_HurtMethod == SkillDamageTypeEnum.HEAL) then
        return IBuffEffect.FAIL;
    end
    if (result:getDamage() <= 0) then
        return IBuffEffect.FAIL;
    end

    SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
    .. buff.modelId .. " 触发护盾BUFF效果，护盾值：" .. buff.pool.current);
    local curr = buff.pool.current
    if (result:getDamage() >= buff.pool.current) then
        result:setDamage(result:getDamage() - buff.pool.current)
        buff.pool:setCurrent(0,buff);
            if (result:getDamage()==0)then
                result.setState(DamageResultTypeEnum.SHIELD.id);
            end
    else
        buff.pool:setCurrent(buff.pool.current - result:getDamage(),buff);
        result:setDamage(0);
        result:setState(DamageResultTypeEnum.SHIELD);
        local commandInfo = ReportManager.buffToJsonString(fight, buff, 3)
        table.insert(fight.actions,commandInfo);
        FightManager.playActions(commandInfo)
    end

    SkillRoleMgr.savePathFile(
    "[" .. fight.frame .. "][DAMAGE]" .. buff.source.fighterId .. "对"
    .. buff.target.fighterId .. "计算BUFF(" .. buff.modelId .. ")减伤伤害[4]结果,减免后伤害: "
    .. NumberFormatUtil.formatDamage(result.damage) .. "  本次护盾抵消:" ..(curr - buff.pool.current));

    if (buff.pool.current <= 0) then
        return IBuffEffect.REMOVE;
    end
    return ClientFight.BaseBuffEffect.action(self,fight, buff, parameters);
end

t.New()